//
//  CYYSponsorPartyViewController.m
//  LetsParty
//
//  Created by rimi on 15/9/11.
//  Copyright (c) 2015年 LetsPartyTeam. All rights reserved.
//

#import "CYYSponsorPartyViewController.h"
#import "CYYDateAlterView.h"
#import "CYYLoadViewController.h"

#define TEXTFIELD_TEXT(_tag) ((UITextField *)[self.view viewWithTag:_tag]).text
#define TEXTVIEW_TEXT(_tag) ((UITextView *)[self.view viewWithTag:_tag]).text
#define TEXTFIELD(_tag) ((UITextField *)[self.view viewWithTag:_tag])

//标题字体大小
//static CGFloat titleFontSize = 20;
//输入框字体大小
static CGFloat textFieldTextSize = 20;
//按钮标题文字大小
static CGFloat buttonTextSize = 14;
//placeholder text font size
static CGFloat placeHolerSize = 14;

@interface CYYSponsorPartyViewController () <UITextViewDelegate, UITextFieldDelegate>

@property (nonatomic, strong) CYYDateAlterView * dateAlterView;//日期选择器
//@property (nonatomic, strong) CYYDateAlterView * dateTwoAlterView;//日期选择器
@property (nonatomic, strong) GmailLikeLoadingView * loadingView;//进度条
@property (nonatomic, strong) UIAlertController * cAlertController;//弹出框

- (void)initializeUserInterface;

@end

@implementation CYYSponsorPartyViewController
#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = COLOR_BackgroundGray;
    self.bartitleLabel.text = @"发起活动";
    self.baseNavigationBar.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.baseNavigationBar];
    //监听键盘:键盘即将出现
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHiden:) name:UIKeyboardWillHideNotification object:nil];
    //已经登陆
    [self initializeUserInterface];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
//    [self.view addSubview:self.dateTwoAlterView];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    //移除通知
    [[NSNotificationCenter defaultCenter] removeObserver:UIKeyboardWillShowNotification];
    [[NSNotificationCenter defaultCenter] removeObserver:UIKeyboardWillHideNotification];
//    [self.dateAlterView removeFromSuperview];
}

#pragma mark - system protocol implentations
- (void)textViewDidChange:(UITextView *)textView{
    //空
    if ([textView.text isEqualToString:@""]) {
        ((UITextField * )[self.view viewWithTag:104]).hidden = NO;
    }else{
        ((UITextField * )[self.view viewWithTag:104]).hidden = YES;
    }
}

//开始事件结束 time
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    [self.view endEditing:YES];
    if (textField.tag == partyBeginTimeContentTextViewTag) {
        __block UITextField * textField = ((UITextField *)[self.view viewWithTag:partyBeginTimeContentTextViewTag]);
        self.dateAlterView.hidden = NO;
        self.dateAlterView.okDateBlock = ^(NSString * dateString){
            textField.text = dateString;
            textField.font = [UIFont systemFontOfSize:13];
        };
    }
    if (textField.tag == partyEndTimeContentTextViewTag) {
        __block UITextField * textField = ((UITextField *)[self.view viewWithTag:partyEndTimeContentTextViewTag]);
        self.dateAlterView.hidden = NO;
        self.dateAlterView.okDateBlock = ^(NSString * dateString){
            textField.text = dateString;
            textField.font = [UIFont systemFontOfSize:13];
        };
    }
    return NO;
}

#pragma mark - private methods
- (void)initializeUserInterface{
    [self.view addSubview:self.mainScrollView];
    [self.view addSubview:self.dateAlterView];
    self.dateAlterView.hidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.dateAlterView.okButton addTarget:self action:@selector(respondsToOkButton:) forControlEvents:UIControlEventTouchUpInside];
    //详情textView
    UITextView * contentTextView = [[UITextView alloc]init];
    contentTextView.backgroundColor = [UIColor whiteColor];
    contentTextView.frame = DHFlexibleFrame(CGRectMake(85, 6 + 50 * 3, 210, 90), NO);
    contentTextView.font = [UIFont systemFontOfSize:textFieldTextSize * DHFlexibleVerticalMutiplier()];
    contentTextView.showsVerticalScrollIndicator = NO;
    contentTextView.bounces = NO;
    contentTextView.keyboardType = UIKeyboardTypeDefault;
    contentTextView.inputAccessoryView = [self customKeyboardToolbar];
    contentTextView.layer.borderWidth = 0.5f;
    contentTextView.layer.borderColor = [UIColor blackColor].CGColor;
    contentTextView.tag = partyDetailTextContentViewTextViewTag;
    contentTextView.layer.masksToBounds = YES;
    contentTextView.layer.cornerRadius = 5;
    contentTextView.delegate = self;
    [self.mainScrollView addSubview:contentTextView];
    //实现contentView的placeholder
    for (int i = 0; i < 6; i ++) {
        UITextField * cTextField = [self haveMyTextFieldByTag:100 + i];
        [self.mainScrollView addSubview:cTextField];
    }
    //其他要求配置
    //标题输入长度限制
    [TEXTFIELD(partyTitleContentTextViewTag)  addTarget:self action:@selector(respondsToLimitLength:) forControlEvents:UIControlEventEditingChanged
     ];
    //开始时间、结束时间
    TEXTFIELD(partyBeginTimeContentTextViewTag).delegate = self;
    TEXTFIELD(partyEndTimeContentTextViewTag).delegate = self;
    //给详情TextView添加PlaceHolder
    TEXTFIELD(partyDetailTextContentTextViewTag).enabled = NO;
    TEXTFIELD(partyDetailTextContentTextViewTag).layer.borderWidth = 0;
    //按钮输入长度限制
    [TEXTFIELD(partySecretCodeContentTextViewTag) addTarget:self action:@selector(respondsToSecretCodeTextField:) forControlEvents:UIControlEventEditingChanged];
    //设置标题label
    for (int i = 0; i < 6; i ++) {
        UILabel * cLabel = [self haveLabelByIndex:i];
        [self.mainScrollView addSubview:cLabel];
        if (i == 5) {
            cLabel.tag = titleLabelTag;
        }
    }
    //按钮
    //地图选点 + 自动生成暗号 + 检测可用性
    for (int i = 0; i < 4 ; i ++) {
        [self.mainScrollView addSubview:[self haveButtonWithtag:106 + i]];
    };
    //隐藏地图按钮
    [self.view viewWithTag:mapSelectedButtonTag].hidden = YES;
    [self.mainScrollView addSubview:self.dateAlterView];
    [self.mainScrollView addSubview:self.loadingView];
}


- (void)sponsorMyParty{
    [self.loadingView stopAnimating];
    self.loadingView.hidden = YES;
    if ([TEXTFIELD_TEXT(partyBeginTimeContentTextViewTag) compare:TEXTFIELD_TEXT(partyEndTimeContentTextViewTag)] == 1) {
        [self alterViewWithMessage:@"活动开始时间不能大于结束时间"];
        [self.view viewWithTag:sponsorButtonTag].userInteractionEnabled = YES;
        return;
    }
    if ([TEXTFIELD_TEXT(partyBeginTimeContentTextViewTag) compare:[CYYNetWorkManager tStringFromDate:[NSDate date]]] == -1) {
        [self alterViewWithMessage:@"活动时间不能小于当前时间"];
        [self.view viewWithTag:sponsorButtonTag].userInteractionEnabled = YES;
        return;
    }
    __weak typeof(self) myVC = self;
    [CYYNetWorkManager sponsorNewPartyWithPartyTitle:TEXTFIELD_TEXT(partyTitleContentTextViewTag)
                                      partyBeginTime:TEXTFIELD_TEXT(partyBeginTimeContentTextViewTag)
                                        partyEndTime:TEXTFIELD_TEXT(partyEndTimeContentTextViewTag)
                                   partyPositionName:TEXTFIELD_TEXT(partyPositionNameContentTextViewTag)
                             partyPositionCoordinate:nil
                                     partyDetailText:TEXTVIEW_TEXT(partyDetailTextContentViewTextViewTag)
                                        partySponsor:[CYYNetWorkManager currentUserGet]
                                     partySecretCode:TEXTFIELD_TEXT(partySecretCodeContentTextViewTag)
                                              sucess:^(NSString *sucessString) {
//                                                  NSLog(@"%@",sucessString);
                                                  [myVC copy:myVC.rightNavButton];
                                                  [myVC alterViewWithMessage:[NSString stringWithFormat:@"%@\n活动复制成功，您可以将活动信息通过粘贴分享给好友。",sucessString]];
                                                  [myVC clearAllDate];
                                                  [myVC.view viewWithTag:sponsorButtonTag].userInteractionEnabled = YES;
                                              }
                                                fail:^(NSError *error) {
                                                    [myVC alterViewWithMessage:@"网络出错"];
                                                    [myVC.view viewWithTag:sponsorButtonTag].userInteractionEnabled = YES;
                                                }];
}
//自动4位生成暗号
- (void)autoCreativeSecrectCode{
    NSString * aString = @"";
    for (int i = 0; i < 4; i ++) {
        NSInteger autoCreativeInterge = arc4random() % 10;
        aString = [aString stringByAppendingFormat:@"%@",[NSString stringWithFormat:@"%ld",(long)autoCreativeInterge]];
    }
    __weak typeof(self) myVC = self;
    //判断4为暗码是否存在
    [CYYNetWorkManager compareSecretCodeWithSecretCode:aString sucess:^(NSInteger sucessNumber) {
        [myVC.loadingView stopAnimating];
        myVC.loadingView.hidden = YES;
        if (sucessNumber == 0) {
            //暗号不重复
//            NSLog(@"暗号可以使用");
            TEXTFIELD_TEXT(partySecretCodeContentTextViewTag) = aString;
            [self.loadingView stopAnimating];
            self.loadingView.hidden = YES;
            [myVC.view viewWithTag:autoCreateButtonTag].userInteractionEnabled = YES;
        }else {
            //重新生成暗号
//            NSLog(@"暗号已经被使用");
            [myVC autoCreativeSecrectCode];
            [self.loadingView stopAnimating];
            self.loadingView.hidden = YES;
            [myVC.view viewWithTag:autoCreateButtonTag].userInteractionEnabled = YES;
        }
    } fail:^(NSError *error) {
        [self.loadingView stopAnimating];
        self.loadingView.hidden = YES;
        [myVC.view viewWithTag:autoCreateButtonTag].userInteractionEnabled = YES;
    }];
}

- (void)checkSecretCodeWithInputeString:(NSString *)string{
    if ([string isEqualToString:@""]) {
        [self alterViewWithMessage:@"请输入暗号"];
        [self.loadingView stopAnimating];
        self.loadingView.hidden = YES;
        //开启交互
        [self.view viewWithTag:checkButtonTag].userInteractionEnabled = YES;
    }else{
        //判断暗码是否存在
        __weak typeof(self) myVC = self;
        [CYYNetWorkManager compareSecretCodeWithSecretCode:string sucess:^(NSInteger sucessNumber) {
            if (sucessNumber == 0) {
                //暗号不重复
//                NSLog(@"暗号可以使用");
                [myVC alterViewWithMessage:@"暗号可以使用"];
                [self.loadingView stopAnimating];
                self.loadingView.hidden = YES;
                //开启交互
                [myVC.view viewWithTag:checkButtonTag].userInteractionEnabled = YES;
            }else {
                //重新生成暗号
//                NSLog(@"暗号已经被使用");
                [myVC alterViewWithMessage:@"暗号已被使用"];
                [self.loadingView stopAnimating];
                self.loadingView.hidden = YES;
                //开启交互
                [myVC.view viewWithTag:checkButtonTag].userInteractionEnabled = YES;
            }
        } fail:^(NSError *error) {
            [myVC alterViewWithMessage:error.domain];
            [self.loadingView stopAnimating];
            self.loadingView.hidden = YES;
            //开启交互
            [myVC.view viewWithTag:checkButtonTag].userInteractionEnabled = YES;
        }];
    }
}

- (void)alterViewWithMessage:(NSString *)message{
    UIAlertController * alterViewController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    [alterViewController addAction:[UIAlertAction actionWithTitle:@"好的，我知道了！" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        [alterViewController dismissViewControllerAnimated:YES completion:nil];
    }]];
    [self presentViewController:alterViewController animated:YES completion:nil];
}

//键盘uitoolbar
- (UIToolbar * )customKeyboardToolbar{
    UIToolbar * toolbar = [[UIToolbar alloc]init];
    toolbar.barTintColor = [UIColor whiteColor];
    toolbar.frame = DHFlexibleFrame(CGRectMake(0, 0, 320, 30), YES);
    //隐藏按钮
    UIBarButtonItem * spaceBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    spaceBarButtonItem.width = 200;
    UIBarButtonItem * rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-bohaojianpanshouqi"] style:UIBarButtonItemStylePlain target:self action:@selector(respondsToDoneButton)];
    rightBarButtonItem.tintColor = [UIColor darkGrayColor];
    toolbar.items = @[spaceBarButtonItem,rightBarButtonItem];
    return toolbar;
}
//发布成功 清空数据
- (void)clearAllDate{
    for (int i = 100; i < 106 ; i ++) {
        TEXTFIELD_TEXT(i) = @"";
    }
    TEXTVIEW_TEXT(partyDetailTextContentViewTextViewTag) = @"";
}
- (UITextField *)haveMyTextFieldByTag:(NSInteger)tag{
    NSArray * frameArrray = @[[NSValue valueWithCGRect:DHFlexibleFrame(CGRectMake(85, 6 + 50 * 0, 210, 30),NO)],
                              [NSValue valueWithCGRect:DHFlexibleFrame(CGRectMake(85, 6 + 50 * 1, 90, 30), NO)],
                              [NSValue valueWithCGRect:DHFlexibleFrame(CGRectMake(85 + 120, 6 + 50 * 1, 90, 30), NO)],
                              [NSValue valueWithCGRect:DHFlexibleFrame(CGRectMake(85, 6 + 50 * 2, 210, 30), NO)],
                              [NSValue valueWithCGRect:DHFlexibleFrame(CGRectMake(87, 86 + 50 * 3 - 50, 200, 30), NO)],
                              [NSValue valueWithCGRect:DHFlexibleFrame(CGRectMake(87, 86 + 50 * 5 - 50, 200, 30), NO)]];
    UITextField * cTextField = [[UITextField alloc]initWithFrame:[frameArrray[tag - 100] CGRectValue]];
    cTextField.backgroundColor = [UIColor whiteColor];
    cTextField.font = [UIFont systemFontOfSize:textFieldTextSize * DHFlexibleVerticalMutiplier()];
    cTextField.keyboardType = UIKeyboardTypeDefault;
    cTextField.inputAccessoryView = [self customKeyboardToolbar];
    cTextField.layer.borderWidth = 0.5f;
    cTextField.layer.borderColor = [UIColor blackColor].CGColor;
    cTextField.layer.masksToBounds = YES;
    cTextField.layer.cornerRadius = 5;
    cTextField.placeholder = @[@"活动标题(少于30字)",@"开始时间",@"结束时间",@"活动地址名称",@"活动详情(可选)",@"活动暗号"][tag - 100];
    cTextField.tag = tag;
    [cTextField setValue:[UIFont boldSystemFontOfSize:placeHolerSize * DHFlexibleVerticalMutiplier()] forKeyPath:@"_placeholderLabel.font"];
    return cTextField;
}

//label
- (UILabel *)haveLabelByIndex:(NSInteger)index{
    NSArray * labelNameArray = @[@"标题:",@"时间:",@"时间:",@"地址:",@"详情:",@"暗号:"];
    UILabel * cLabel = [[UILabel alloc]init];
    cLabel.frame = CGRectMake(20 * DHFlexibleVerticalMutiplier(), TEXTFIELD(100 + index).frame.origin.y, 50 * DHFlexibleHorizontalMutiplier(), 30 * DHFlexibleVerticalMutiplier());
    cLabel.text = labelNameArray[index];
    return cLabel;
}

//button
- (UIButton *)haveButtonWithtag:(NSInteger)tag{
    //frame
    NSArray * frameArray = @[
                             [NSValue valueWithCGRect:CGRectMake(85 * DHFlexibleVerticalMutiplier(), CGRectGetMaxY(((UITextField *)[self.view viewWithTag:partyPositionNameContentTextViewTag]).frame) + 20 * DHFlexibleVerticalMutiplier(), 30 * DHFlexibleHorizontalMutiplier(), 30 * DHFlexibleVerticalMutiplier())],
                             [NSValue valueWithCGRect:CGRectMake(85 * DHFlexibleVerticalMutiplier(), CGRectGetMaxY(((UITextField *)[self.view viewWithTag:partySecretCodeContentTextViewTag]).frame) + 20 * DHFlexibleVerticalMutiplier(), 90 * DHFlexibleHorizontalMutiplier(), 30 * DHFlexibleVerticalMutiplier())],
                             [NSValue valueWithCGRect:CGRectMake(205 * DHFlexibleVerticalMutiplier(),  CGRectGetMaxY(((UITextField *)[self.view viewWithTag:partySecretCodeContentTextViewTag]).frame) + 20 * DHFlexibleVerticalMutiplier(), 90 * DHFlexibleHorizontalMutiplier(), 30 * DHFlexibleVerticalMutiplier())],
                             [NSValue valueWithCGRect:CGRectMake(115 * DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(((UITextField *)[self.view viewWithTag:partySecretCodeContentTextViewTag]).frame) + 80 * DHFlexibleVerticalMutiplier(), 90 * DHFlexibleHorizontalMutiplier(), 30 * DHFlexibleVerticalMutiplier())]];
    //图片
    //title
    NSArray * imageNameArray = @[@"地图选点",@"自动生成暗号",@"检测可用性",@"发布"];
    UIButton * cButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cButton.frame = [frameArray[tag - 106] CGRectValue];
    cButton.tag = tag;
    cButton.backgroundColor = COLOR_TagBlue;
    [cButton setTitle:imageNameArray[tag - 106] forState:UIControlStateNormal];
//    [cButton setImage:[UIImage imageNamed:@"iconfont-ditu (1)"] forState:UIControlStateNormal];
    cButton.titleLabel.font = [UIFont systemFontOfSize:buttonTextSize * DHFlexibleVerticalMutiplier()];
    cButton.layer.cornerRadius = 5;
    cButton.layer.masksToBounds = YES;
    [cButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cButton addTarget:self action:@selector(respondsToSelectorButton:) forControlEvents:UIControlEventTouchUpInside];
    return cButton;
}

#pragma mark - responds event
- (void)respondsToSelectorButton:(UIButton *)button{
    switch (button.tag) {
        case mapSelectedButtonTag:
//            [[ControllerManager sharedManager].rootViewController pushViewController:[[HFMapViewController alloc]init] animated:YES];
            break;
        case checkButtonTag:{
            button.userInteractionEnabled = NO;//关闭交互
            self.loadingView.hidden = NO;
            [self.loadingView startAnimating];
            [self checkSecretCodeWithInputeString:TEXTFIELD_TEXT(partySecretCodeContentTextViewTag)];
        }
            break;
        case autoCreateButtonTag:{
            button.userInteractionEnabled = NO;//关闭交互
            self.loadingView.hidden = NO;
            [self.loadingView startAnimating];
            [self autoCreativeSecrectCode];
        }
            break;
        case sponsorButtonTag:{
            button.userInteractionEnabled = NO;//关闭交互
            self.loadingView.hidden = NO;
            [self.loadingView startAnimating];
            [self sponsorMyParty];
        }
            
            break;
    }
}
- (void)keyboardWillShow:(NSNotification *) notification{
    self.mainScrollView.frame = CGRectMake(0, 64 * DHFlexibleVerticalMutiplier(), 320 * DHFlexibleHorizontalMutiplier(), (460 + 44) * DHFlexibleVerticalMutiplier() - [((NSValue * )((NSDictionary * )[notification userInfo])[@"UIKeyboardBoundsUserInfoKey"]) CGRectValue].size.height);
}
- (void)keyboardWillHiden:(NSNotification *) notification{
    self.mainScrollView.frame = DHFlexibleFrame(CGRectMake(0, 64, 320, 460), NO);
}
//处理键盘隐藏事件
- (void)respondsToDoneButton{
    [self.view endEditing:YES];
}
//处理textField弹出框
- (void)respondsToTapGesture:(UITapGestureRecognizer *)tapGesture{
    [self.view endEditing:YES];
    if (tapGesture.view.tag == partyBeginTimeMaskviewTag) {
        __block UITextField * textField = ((UITextField *)[self.view viewWithTag:partyBeginTimeContentTextViewTag]);
        self.dateAlterView.hidden = NO;
        self.dateAlterView.okDateBlock = ^(NSString * dateString){
            textField.text = dateString;
            textField.font = [UIFont systemFontOfSize:13];
//            NSLog(@"%@",dateString);
        };
    }else{
        __block UITextField * textField = ((UITextField *)[self.view viewWithTag:partyEndTimeContentTextViewTag]);
        self.dateAlterView.hidden = NO;
        self.dateAlterView.okDateBlock = ^(NSString * dateString){
            textField.text = dateString;
            textField.font = [UIFont systemFontOfSize:13];
//            NSLog(@"%@",dateString);
        };
    }

}

//限制输入的长度30
- (void)respondsToLimitLength:(UITextField *)textField{
    if(textField.text.length > 30){
        textField.text = [textField.text substringToIndex:30];
    }
}
//限制暗号的长度15
- (void)respondsToSecretCodeTextField:(UITextField *)textField{
    if (textField.text.length > 15) {
        textField.text = [textField.text substringToIndex:15];
    }
}

- (void)respondsToOkButton:(UIButton *)button{
    //date转换成string
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy/MM/dd"];
    NSString * dateString = [dateFormatter stringFromDate:self.dateAlterView.datePicker.date];
    self.dateAlterView.okDateBlock(dateString);
    self.dateAlterView.hidden = YES;
}

#pragma mark - ovride
- (void)copy:(id)sender{
    UIPasteboard * pasteBoard = [UIPasteboard generalPasteboard];
    [pasteBoard setString:[NSString stringWithFormat:@"%@,%@ - %@,%@,暗号:%@",TEXTFIELD_TEXT(partyTitleContentTextViewTag),TEXTFIELD_TEXT(partyBeginTimeContentTextViewTag),TEXTFIELD_TEXT(partyEndTimeContentTextViewTag),TEXTFIELD_TEXT(partyPositionNameContentTextViewTag),TEXTFIELD_TEXT(partySecretCodeContentTextViewTag)]];
}

#pragma mark - getter
-(UIScrollView *)mainScrollView{
    if (!_mainScrollView) {
        _mainScrollView = ({
            UIScrollView * scrollView = [[UIScrollView alloc]init];
            scrollView.backgroundColor = COLOR_RGB(231, 231, 235, 1);
            scrollView.frame = DHFlexibleFrame(CGRectMake(0, 64, 320, 504), NO);
            scrollView.contentSize = DHFlexibleSize(CGSizeMake(320, 504), NO);
            scrollView.bounces = NO;
            scrollView;
        });
    }
    return _mainScrollView;
}

- (CYYDateAlterView *)dateAlterView{
    if (!_dateAlterView) {
        _dateAlterView = ({
            CYYDateAlterView * dateAlterView = [[CYYDateAlterView alloc]init];
            dateAlterView;
        });
    }
    return _dateAlterView;
}

- (GmailLikeLoadingView *)loadingView{
    if (!_loadingView) {
        _loadingView = ({
            GmailLikeLoadingView * cLoadView = [[GmailLikeLoadingView alloc]initWithFrame:CGRectMake(320*0.5 - 12, 568*0.5 - 12, 15, 15) adjustWidth:YES];
            [_loadingView setHidden:YES];
            cLoadView;
        });
    }
    return _loadingView;
}

@end


